package com.ssms.controller;

import com.ssms.commons.Result;
import com.ssms.commons.TablePage;
import com.ssms.model.Academy;
import com.ssms.service.AcademyService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/academy")
public class AcademyController {

    @Resource
    private AcademyService academyService;

    @RequestMapping()
    public String academy() {
        return "academy";
    }

    @RequestMapping("list")
    @ResponseBody
    public TablePage list(TablePage tablePage, @RequestParam(value = "searchValue",required = false) String searchValue) {
        return academyService.search(tablePage, searchValue);
    }

    @RequestMapping("all")
    @ResponseBody
    public Result all() {
        return academyService.all();
    }

    @RequestMapping("add")
    @ResponseBody
    public Result add(Academy academy) {
        return academyService.save(academy);
    }

    @RequestMapping("update")
    @ResponseBody
    public Result update(Academy academy) {
        return academyService.update(academy);
    }

    @RequestMapping("delete")
    @ResponseBody
    public Result delete(Integer id) {
        return academyService.delete(id);
    }

    @RequestMapping("academyTree")
    @ResponseBody
    public Result academyTree() {
        return Result.success(academyService.getAcademyTree());
    }

    @RequestMapping("academyTree2")
    @ResponseBody
    public Result academyTree2() {
        return Result.success(academyService.getAcademyTree2());
    }
}
